package com.sunny.spring_boot_test.configuration;

import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;
import org.springframework.stereotype.Component;

@Component
public class TableNameStrategy extends SpringPhysicalNamingStrategy {

    /**
     * 自定义表名转换
     *
     * @param name
     * @param jdbcEnvironment
     * @return
     */
    @Override
    public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment jdbcEnvironment) {
        String tableName = "tb_" + name.getText();
        return Identifier.toIdentifier(tableName);
    }
}